package com.wl156.adapters;

import org.ksoap2.serialization.SoapObject;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wl156.lite.R;

public class MyPublishMessageAdapter extends CheckableAdapter implements
		OnClickListener {

	public MyPublishMessageAdapter(Context context, SoapObject data) {
		mInflater = LayoutInflater.from(context);
		mData = data;
		mContext = context;
	}
	
	public String getType(int position) {
		return getItem(position).getProperty(5).toString();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater
					.inflate(R.layout.item_my_message, null);
		}

		// 04-25 23:30:10.996: D/(19800): result:
		// anyType{ArrayOfString=anyType{string=粤C76534; string=其它; string=21;
		// string=121; string=何生; string=1345667881; string=null; }; }, type:
		// SoapObject
		// 顺序是：id, 车片号，车型，吨位，车长，联系人，联系电话，货运需求

		/*
		 * /// 流水号 /// 标题 /// 出发地省市区 /// 目的地省市区 /// 状态 /// 类型 /// 发布日期
		 */

		try {
			TextView title = (TextView) convertView.findViewById(R.id.title);
			TextView from = (TextView) convertView.findViewById(R.id.from);
			TextView to = (TextView) convertView.findViewById(R.id.to);

			TextView state = (TextView) convertView
					.findViewById(R.id.state);
			TextView date = (TextView) convertView
					.findViewById(R.id.date);
			TextView type = (TextView) convertView.findViewById(R.id.type);

//			TextView phoneDial = (TextView) convertView.findViewById(R.id.dial);
//			phoneDial.setOnClickListener(this);

			setTextViewStringFromProperty(position, title, 1);
			setTextViewStringFromProperty(position, from, 2);
			setTextViewStringFromProperty(position, to, 3);
			setTextViewStringFromProperty(position, state, 4);
			setTextViewStringFromProperty(position, type, 5);
			setTextViewStringFromProperty(position, date, 6);
//			setTextViewStringFromProperty(position, need, 7);
//			setPhoneView(position, phoneDial, 6);
		} catch (Exception e) {
		}

		super.getView(position, convertView, parent);

		return convertView;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.dial:
			Intent i = new Intent(Intent.ACTION_CALL);
			i.setData(Uri.parse("tel:" + v.getTag().toString()));
			mContext.startActivity(i);
			break;
		}
	}
}
